package com.study.test;

import javax.swing.*;
import java.awt.event.*;
import java.lang.classfile.instruction.ThrowInstruction;
import java.util.Random;

public class MyJFrame2 extends JFrame implements MouseListener {
    //创建一个按钮对象
    JButton jtb1=new JButton("按钮");



    public MyJFrame2() {
        //设置界面的宽高
        this.setSize(603, 680);

        //设置界面的标题
        this.setTitle("拼图游戏v1.0");

        //设置界面置顶
        this.setAlwaysOnTop(true);

        //设置界面居中
        this.setLocationRelativeTo(null);

        //设置界面关闭
        this.setDefaultCloseOperation(3);

        //取消默认的居中放置
        this.setLayout(null);



        //设置位置宽高
        jtb1.setBounds(0, 0, 100, 50);

        //给按钮绑定鼠标事件
        jtb1.addMouseListener(this);





        //按钮添加到界面当中
        this.getContentPane().add(jtb1);


        //显示界面
        this.setVisible(true);


    }


    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("鼠标点击了");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("鼠标按下了");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("鼠标松开了");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("鼠标进入了");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("鼠标离开了");
    }
}

